package net.xdclass.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import net.xdclass.enums.DomainTypeEnum;
import net.xdclass.manager.DomainManager;
import net.xdclass.mapper.DomainMapper;
import net.xdclass.model.DomainDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class DomainManagerImpl implements DomainManager {
	@Autowired
	private DomainMapper domainMapper;
	@Override
	public DomainDO findById(Long id, Long accountNO) {
		DomainDO domainDO = domainMapper.selectOne(new QueryWrapper<DomainDO>()
		.eq("id",id)
		.eq("account_no",accountNO));
		return domainDO;
	}
	@Override
	public DomainDO findByDomainTypeAndID(Long id, DomainTypeEnum domainTypeEnum) {
		DomainDO domainDO = domainMapper.selectOne(new QueryWrapper<DomainDO>()
				.eq("id",id).eq("domain_type",domainTypeEnum.name())
		);
		return domainDO;	}

	@Override
	public int addDomain(DomainDO domainDO) {
		int rows = domainMapper.insert(domainDO);
		return rows;
	}

	@Override
	public List<DomainDO> listOfficialDomain() {
		List <DomainDO> doaminList = domainMapper.selectList(new QueryWrapper<DomainDO>()
				.eq("domain_type",DomainTypeEnum.OFFICIAL.name()));
		return doaminList ;
	}

	@Override
	public List<DomainDO> listCustomDomain(Long accountNo) {
		List <DomainDO> customList = domainMapper.selectList(new QueryWrapper<DomainDO>()
				.eq("domain_type", DomainTypeEnum.CUSTOM.name())
				.eq("account_no","accountNo"));
		return customList;
	}
}
